#include "rtc.h"
#include "time.h"
void time_sycn()
{
	RTC_TimeTypeDef sTime = {0};
	RTC_DateTypeDef sDate = {0};

	sTime.Hours = 12;
	sTime.Minutes = 0;
	sTime.Seconds = 0;
	HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN);

	sDate.WeekDay = RTC_WEEKDAY_MONDAY;
	sDate.Month   = 8;
	sDate.Date    = 31;
	sDate.Year    = 25;   // 表示 2025 年
	HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN);
}

void get_time()
{
	RTC_DateTypeDef sDate;
    RTC_TimeTypeDef sTime;
    struct tm timeinfo;

    HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
    HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN);

    timeinfo.tm_year = sDate.Year + 100;   // 偏移到 2000-2099
    timeinfo.tm_mon  = sDate.Month - 1;
    timeinfo.tm_mday = sDate.Date;
    timeinfo.tm_hour = sTime.Hours;
    timeinfo.tm_min  = sTime.Minutes;
    timeinfo.tm_sec  = sTime.Seconds;

   time_t time = mktime(&timeinfo);
}